'''
Created on Oct 9, 2011

@author: solagna
'''
import WebDownloader.webPage

class bdiiList(object):
    '''
    classdocs
    '''
    __bdiiUrl__ = "https://wiki.egi.eu/wiki/Top-BDII_list_for_NGI"
    __wikiTable__ = []
    __allBDIIs__ = []
    __ngisBDII__ = {}
 
    def __init__(self):
        '''
        Constructor
        '''
        #Get the list of BDIIs from the wiki page.
        wikiBDIIs = WebDownloader.webPage.webPage(self.__bdiiUrl__)
        self.__wikiTable__ = wikiBDIIs.returnTableX(3)
        
        # Split all BDIIs in a single list. populate allBDIIs and ngisBDIIs
        for wikiRow in self.__wikiTable__:
            
            try:
                wikiRow = [x.strip(' ') for x in wikiRow]
                wikiList = wikiRow[1].split(",")
                wikiList = [x.lstrip(' ') for x in wikiList]
                self.__allBDIIs__.extend(wikiList)
                self.__ngisBDII__[wikiRow[0]] = wikiList
            except:
                pass
    def returnAllNGIs (self):
        return sorted(self.__ngisBDII__.keys())
            
    def returnNgiBDII (self, ngi_name):
        return self.__ngisBDII__[ngi_name]
    
    def returnAllBDII (self):
        return self.__allBDIIs__
    
if __name__ == "__main__":
    #Download all.
    #x.printPage()
    x = bdiiList()
    
    #print x.returnAllBDII()
    print x.returnAllNGIs()
    print x.returnNgiBDII ("AfricaArabia")
